<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;

use app\portal\service\PostService;
use cmf\controller\HomeBaseController;
use app\portal\model\PortalCategoryModel;
use think\Db;

class ListController extends HomeBaseController
{
    public function index()
    {

        $id                  = $this->request->param('id', 0, 'intval');
        $id=!empty($id)?$id:8;
        //echo $id;
        $portalCategoryModel = new PortalCategoryModel();

        $category = $portalCategoryModel->where('id', $id)->where('status', 1)->find();
        //   echo $portalCategoryModel->getLastSql();

       //print_r($category);exit;
        $type=$portalCategoryModel->where('parent_id',$id)->where('status', 1)->select();
        $types=$portalCategoryModel->where('parent_id',$id)->where('status', 1)->find();

        $this->assign('type', $type);
        $cid                = $this->request->param('cid', 0, 'intval');

            $cid=!empty($cid)?$cid:$types['id'];


        $portalCategoryModel = new PortalCategoryModel();


        $category = $portalCategoryModel->where('id', $cid)->where('status', 1)->find();
        $this->assign('category', $category);
         //  echo $portalCategoryModel->getLastSql();
        $list=Db::name("portal_post")->alias("b")
            ->join("portal_category_post a",'a.post_id=b.id')->where("a.category_id",$category['id'])->paginate(16);

        $this->assign('list', $list);
       // print_r($list);exit;
        $listTpl = empty($category['list_tpl']) ? 'list' : $category['list_tpl'];

        return $this->fetch('/' . $listTpl);
    }

}
